<!--********************************************************************
* Copyright© 2000 - 2018 SuperMap Software Co.Ltd. All rights reserved.
*********************************************************************-->
<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title data-i18n="resources.title_popDensityRange"></title>
    <style type="text/css">
        .legendItemHeader,
        .legendItemValue {
            width: 120px;
            height: 18px;
            font-size: 14px;
        }
    </style>
</head>
<body style=" margin: 0;overflow: hidden;background: #fff;width: 100%;height:100%;position: absolute;top: 0;">
<div id="map" style="width: 100%;height:100%">
    <div style="z-index: 100;position: relative;width: 272px;float:right">
        <div id="infoBox" class="panel panel-primary infoPane"
             style="width:272px;margin-top: 250px;position: absolute;fontSize:14px;display: none;float:right">
            <div class="panel-heading">
                <h5 class='panel-title text-center' data-i18n="resources.text_attributeTable"></h5>
            </div>
            <div id="infoContent" class="panel-body content">
            </div>
        </div>
        <div class="panel panel-primary legend" style="width:272px;margin-top: 400px;position: absolute;float:right">
            <div id="mapLegend" class="panel-heading">
                <h5 class='panel-title text-center'>
                    <span data-i18n="resources.text_legend"></span>
                </h5>
            </div>
            <div class="panel-body text-center">
                <table>
                    <tr>
                        <td class="legendItemHeader" data-i18n="resources.text_populationDensity"></td>
                        <td class="legendItemValue" data-i18n="resources.text_color"></td>
                    </tr>
                    <tr>
                        <td class="legendItemHeader">0 - 0.02</td>
                        <td class="legendItemValue" style="background: #FDE2CA"></td>
                    </tr>
                    <tr>
                        <td class="legendItemHeader">0.02 - 0.04</td>
                        <td class="legendItemValue" style="background: #FACE9C"></td>
                    </tr>
                    <tr>
                        <td class="legendItemHeader">0.04 - 0.06</td>
                        <td class="legendItemValue" style="background: #F09C42"></td>
                    </tr>
                    <tr>
                        <td class="legendItemHeader">0.06 - 0.1</td>
                        <td class="legendItemValue" style="background: #D0770B"></td>
                    </tr>
                    <tr>
                        <td class="legendItemHeader">0.1 - 0.2</td>
                        <td class="legendItemValue" style="background: #945305"></td>
                    </tr>
                </table>
            </div>
        </div>
    </div>
</div>
<script type="text/javascript" include="bootstrap,widgets.alert" src="../js/include-web.js"></script>
<script type="text/javascript" src="../../dist/openlayers/include-openlayers.js"></script>
<script type="text/javascript">
    var map, themeSource
    baseUrl = (window.isLocal ? window.server : "http://iclsvr.supermap.io") + "/iserver/services/map-jingjin/rest/maps/京津地区地图",
        url2 = (window.isLocal ? window.server : "http://iclsvr.supermap.io") + "/iserver/services/data-jingjin/rest/data",
        extent = [104.07, 30.54, 119.51, 42.31];
    new ol.supermap.MapService(baseUrl).getMapInfo(function (serviceResult) {
        var mapJSONObj = serviceResult.result;
        map = new ol.Map({
            target: 'map',
            controls: ol.control.defaults({attributionOptions: {collapsed: false}})
                .extend([new ol.supermap.control.Logo()]),
            view: new ol.View({
                center: [116.85, 39.79],
                zoom: 8,
                projection: "EPSG:4326",
                extent: extent
            })
        });
        var options = ol.source.TileSuperMapRest.optionsFromMapJSON(baseUrl, mapJSONObj);
        var layer = new ol.layer.Tile({
            source: new ol.source.TileSuperMapRest(options)
        });
        map.addLayer(layer);

        var getFeatureParam, getFeatureBySQLService, getFeatureBySQLParams;
        getFeatureParam = new SuperMap.FilterParameter({
            name: "Jingjin",
            attributeFilter: "SMID > -1"
        });
        getFeatureBySQLParams = new SuperMap.GetFeaturesBySQLParameters({
            queryParameter: getFeatureParam,
            toIndex: 500,
            datasetNames: ["Jingjin:BaseMap_R"]
        });
        getFeatureBySQLService = new SuperMap.GetFeaturesBySQLService(url2, {
            format: SuperMap.DataFormat.ISERVER,
            eventListeners: {"processCompleted": processCompleted, "processFailed": processFailed}
        });
        getFeatureBySQLService.processAsync(getFeatureBySQLParams);
    });

    function processCompleted(getFeaturesEventArgs) {
        var result = getFeaturesEventArgs.result;
        if (result && result.features) {
            addThemeLayer();
            themeSource.addFeatures(result.features);
            //显示图例
            document.getElementById("mapLegend").style.display = "block";
        }
    }

    function addThemeLayer() {
        themeSource = new ol.source.Range("ThemeLayer",
            {
                map: map,
                attributions: " ",
                style: {
                    shadowBlur: 16,
                    shadowColor: "#000000",
                    fillColor: "#FFFFFF"
                },
                isHoverAble: true,
                highlightStyle: {
                    stroke: true,
                    strokeWidth: 4,
                    strokeColor: 'blue',
                    fillColor: "#00EEEE",
                    fillOpacity: 0.8
                },
                themeField: "POP_DENSITY99",
                styleGroups: [
                    {
                        start: 0,
                        end: 0.02,
                        style: {
                            color: '#FDE2CA'
                        }
                    },
                    {
                        start: 0.02,
                        end: 0.04,
                        style: {
                            color: '#FACE9C'
                        }
                    },
                    {
                        start: 0.04,
                        end: 0.06,
                        style: {
                            color: '#F09C42'
                        }
                    },
                    {
                        start: 0.06,
                        end: 0.1,
                        style: {
                            color: '#D0770B'
                        }
                    },
                    {
                        start: 0.1,
                        end: 0.2,
                        style: {
                            color: '#945305'
                        }
                    }]
            });
        //专题图层 mousemove 事件
        themeSource.on('mousemove', function (e) {
            if (e.target && e.target.refDataID) {
                document.getElementById("infoBox").style.display = "block";
                var fid = e.target.refDataID;
                var fea = themeSource.getFeatureById(fid);
                if (fea) {
                    document.getElementById("infoContent").innerHTML = "";
                    document.getElementById("infoContent").innerHTML += "ID: " + fea.attributes.SMID + "<br/>";
                    document.getElementById("infoContent").innerHTML += resources.text_districtName + fea.attributes.NAME + "<br/>";
                    document.getElementById("infoContent").innerHTML += resources.text_densityOfPopulation + parseFloat(fea.attributes.POP_DENSITY99).toFixed(5) + "<br/>";
                }
            }
            else {
                document.getElementById("infoContent").innerHTML = "";
                document.getElementById("infoBox").style.display = "none";
            }
        });

        var pointerInteraction = new ol.interaction.Pointer({
            handleMoveEvent: function (event) {
                themeSource.fire('mousemove', event);
            }
        });
        map.addInteraction(pointerInteraction);
        var themeLayer = new ol.layer.Image({
            source: themeSource
        });
        themeLayer.setOpacity(0.8);
        map.addLayer(themeLayer);
    }

    function processFailed(e) {
        widgets.alert.showAlert(e.error.errorMsg, false);
    }
</script>
</body>
</html>